package com.wang.interview.threads;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: wang
 * @date: 2021/7/25 11:36
 * @description: ArrayList 是线程不安全的
 */
public class ArrayListTest {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        ExecutorService po = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {
            po.execute(()-> list.add(1));
        }
        for (int i = 0; i < 10; i++) {
            po.execute(() -> System.out.println(list));  // java.util.ConcurrentModificationException
        }
        po.shutdown();
    }
}
